def convert_base(num_str, from_base, to_base):
    # 将任意进制的数转换为10进制
    num_in_base_10 = int(num_str, from_base)

    # 将10进制转换为目标进制
    if to_base == 10:
        return str(num_in_base_10)
    else:
        # 递归函数转换为目标进制
        def to_target_base(n, base):
            convert_str = "0123456789ABCDEF"
            if n < base:
                return convert_str[n]
            else:
                return to_target_base(n // base, base) + convert_str[n % base]

        return to_target_base(num_in_base_10, to_base)


# 举个例子：将16进制的'1A'转换为2进制
convert_base('1A', 16, 2)
